package gao.xiaolei.dao;

import gao.xiaolei.entity.Image;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository("ImageDao")
public interface InterfaceImageDao extends JpaRepository<Image, String> {

	// 更改图片的引用次数
	@Modifying//update或者delete操作，在更新或者删除操作时，此注解必须加
	@Query(value = "update Image set leadConut = :leadConut where hashCode = :hashCode")
	public void updateLeadCount(@Param("leadConut") int leadCount, @Param("hashCode") String hashCode);

	// 更改图片的下载次数
	@Modifying//update或者delete操作，在更新或者删除操作时，此注解必须加
	@Query(value = "update Image set downloadConut = :downloadConut where hashCode = :hashCode")
	public void updateDownloadCount(@Param("downloadConut") int downloadCount, @Param("hashCode") String hashCode);

	//获取引用次数
	@Query(value="select leadConut from Image where hashCode=:hashCode")
	public Integer getLeadCount(@Param("hashCode") String hashCode);

	//获取下载次数
	@Query(value="select downloadConut from Image where hashCode=:hashCode")
	public Integer getDownLoadCount(@Param("hashCode") String hashCode);
}
